
import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import get from '@dfeidao/atom-web/local/get';
import set from '@dfeidao/atom-web/local/set';

import render from '@dfeidao/atom-web/render/render';

import remove from '@dfeidao/atom-web/local/remove';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import p002 from './p002';
import p003 from './p003';
// import show_loading from '../../atom-web/show-loading';
// import hide_loading from '../../atom-web/hide-loading';
export default async function a007(fd: IFeidaoAiBrowserComponent, args: string) {
	// const id = fd.data._id;
	const id = get(fd, '_id');
	// const user = await whoami(get_user_info);
	// console.log(user)
	const prid = get(fd, 'productid');
	// sysobjarr
	const tab = args;
	// show_loading();
	if (tab === 'tab1') {
		// hide_loading();
	} else if (tab === 'tab2') {
		// const res = await nodejs<{ length: number }>(url, './permissions/role_type_find3', { id, productid: prid }, false, false);
		// hide_loading();

		const res = await nodejs<{ length: number, dataArray: object[] }>('role-type/zj-000004/s003', { id, productid: prid });
		const arr = new Array();
		res.dataArray.forEach((v: { field: string }) => {
			arr.push(v.field);
		});
		set(fd, 'arr', arr);
		// console.log(arr, '007');
		if (res.length !== 0) {
			render(fd, res.dataArray, p002, 'p002', 'inner');
			// delete fd.data.w_id;
			remove(fd, 'w_id');
		} else {
			render(fd, '', p002, 'p002', 'inner');
		}
	} else if (tab === 'tab3') {
		// const res = await nodejs<{ length: number }>(url, './permissions/role_type_find4', { id, productid: prid }, false, false);
		// hide_loading();
		const res = await nodejs<{ length: number, dataArray: object[] }>('role-type/zj-000004/s004', { id, productid: prid });
		const role_sysarr = new Array();
		res.dataArray.forEach((v: { field: string }) => {
			role_sysarr.push(v.field);
		});
		// console.log(role_sysarr, '000');

		set(fd, 'role_sysarr', role_sysarr);
		if (res.length !== 0) {
			render(fd, res.dataArray, p003, 'p003', 'inner');
			// delete fd.data.w_id;
			remove(fd, 'w_id');
		} else {
			render(fd, '', p003, 'p003', 'inner');
		}
	}
}
